package com.xian.im.modules.mis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @program: xian-im-server
 * @description: miss
 * @author: liru.xian
 * @create: 2021-02-05 14:26
 **/
@Slf4j
@Component
public class BlackProcess {

    public static final String KEY = "xim:black:ip:";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     *
     * @param ipAddress
     * @return
     */
    public boolean dealRequest(String ipAddress){

        return redisTemplate.opsForHash().hasKey(KEY, ipAddress);
    }
    public boolean remove(String ipAddress){
        redisTemplate.opsForHash().delete(KEY, ipAddress);
        return Boolean.TRUE;
    }
    public Boolean add(String ipAddress){
        redisTemplate.opsForHash().put(KEY,ipAddress,"1");
        return Boolean.TRUE;
    }
    public Set<String>  getAll(){
        return  redisTemplate.opsForHash().keys(KEY);
    }

}
